Searching is a core feature of Manticore Search. You can:
- Perform full-text search and implement search result highlighting
- Perform k-nearest neighbor search
- Apply non-full-text filtering
- Use expressions for filtering
- Utilize various search options
- Employ multi-queries and sub-selects
- Conduct aggregations and faceting of search results
- And much more
SQL:
SELECT
select_expr [, select_expr] ...
[FROM tbl_name
[{INNER | LEFT} JOIN tbl2_name]
[WHERE where_condition]
[GROUP BY {col_name | expr}, ... ]
[HAVING where_condition]
[ORDER BY {col_name | expr}
[ASC | DESC], ... ]
]
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
[OPTION option1[, option2] ...]
JSON:
POST /search
{
"table" : "table_name",
"options":
{
...
}
}
⪢ Full-text matching
The MATCH
clause allows for full-text searches in text fields. The input query string is tokenized using the same settings applied to the text during indexing. In addition to the tokenization of input text, the query string supports a number of full-text operators that enforce various rules on how keywords should provide a valid match.
Full-text match clauses can be combined with attribute filters as an AND boolean. OR relations between full-text matches and attribute filters are not supported.
The match query is always executed first in the filtering process, followed by the attribute filters. The attribute filters are applied to the result set of the match query. A query without a match clause is called a fullscan.
There must be at most one MATCH()
in the SELECT
clause.
Using the full-text query syntax, matching is performed across all indexed text fields of a document, unless the expression requires a match within a field (like phrase search) or is limited by field operators.
SELECT * FROM myindex WHERE MATCH('cats|birds');
The SELECT statement uses a MATCH clause, which must come after WHERE, for performing full-text searches. MATCH()
accepts an input string in which all full-text operators are available.
- SQL
- MATCH with filters
SELECT * FROM myindex WHERE MATCH('"find me fast"/2');
+------+------+----------------+
| id | gid | title |
+------+------+----------------+
| 1 | 11 | first find me |
| 2 | 12 | second find me |
+------+------+----------------+
2 rows in set (0.00 sec)
Full-text matching is available in the /search
endpoint and in HTTP-based clients. The following clauses can be used for performing full-text matches:
"match" is a simple query that matches the specified keywords in the specified fields.
"query":
{
"match": { "field": "keyword" }
}
You can specify a list of fields:
"match":
{
"field1,field2": "keyword"
}
Or you can use _all
or *
to search all fields.
You can search all fields except one using "!field":
"match":
{
"!field1": "keyword"
}
By default, keywords are combined using the OR operator. However, you can change that behavior using the "operator" clause:
"query":
{
"match":
{
"content,title":
{
"query":"keyword",
"operator":"or"
}
}
}
"operator" can be set to "or" or "and".
The boost
modifier can also be applied. It raises the word IDF_score by the indicated factor in ranking scores that incorporate IDF into their calculations. It does not impact the matching process in any manner.
"query":
{
"match":
{
"field1":
{
"query": "keyword",
"boost": 2.0
}
}
}
"match_phrase" is a query that matches the entire phrase. It is similar to a phrase operator in SQL. Here's an example:
"query":
{
"match_phrase": { "_all" : "had grown quite" }
}
"query_string" accepts an input string as a full-text query in MATCH()
syntax.
"query":
{
"query_string": "Church NOTNEAR/3 street"
}
"match_all" accepts an empty object and returns documents from the table without performing any attribute filtering or full-text matching. Alternatively, you can just omit the query
clause in the request which will have the same effect.
"query":
{
"match_all": {}
}
All full-text match clauses can be combined with must, must_not, and should operators of a JSON bool
query.
- match
- match_phrase
- query_string
- PHP
- Python
- javascript
- Java
- C#
- TypeScript
- Go
POST /search
-d
'{
"table" : "hn_small",
"query":
{
"match":
{
"*" : "find joe"
}
},
"_source": ["story_author","comment_author"],
"limit": 1
}'
{
"took" : 3,
"timed_out" : false,
"hits" : {
"hits" : [
{
"_id": 668018,
"_score" : 3579,
"_source" : {
"story_author" : "IgorPartola",
"comment_author" : "joe_the_user"
}
}
],
"total" : 88063,
"total_relation" : "eq"
}
}